﻿using BussinessObject.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;
using DataAccess.ObjectTwo;

namespace ProjectHK3.Object_One
{
    public partial class Branch : System.Web.UI.Page
    {
        B_LoadGidAD ex = new B_LoadGidAD();
        B_AdminDetail fx = new B_AdminDetail();
        B_LoadDrop ef = new B_LoadDrop();
        DataTable tb = new DataTable();
        B_Delete bd = new B_Delete();
        B_Search bs = new B_Search();
        D_GetAccount dg = new D_GetAccount();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Label7.Text = fx.getBRANCHES().ToString();
                GridView1.DataSource = ex.loadBranch();
                GridView1.DataBind();
                loadData();

            }
        }
        public void loadData()
        {
            DropDownList1.DataSource = ef.city();
            DropDownList1.DataTextField = "CITY_NAME";
            DropDownList1.DataValueField = "CITY_ID";
            DropDownList1.DataBind();
        }
        public void loadGR1()
        {
            _grwAllEmployee.DataSource = bs.loadEmploy(int.Parse(Session["Acc"].ToString()));
            _grwAllEmployee.DataBind();
        }
        protected void _lbtDelete_Click(object sender, EventArgs e)
        {

        }

        protected void _lbtViewDetails_Click(object sender, EventArgs e)
        {

        }

        protected void _lbtViewEmployees_Click(object sender, EventArgs e)
        {
            
        }

        protected void _lbtDelete_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "DeleteBranch")
            {


                Session["Bran"] = Convert.ToInt32(e.CommandArgument.ToString());
                if (bd.DeleteBran(Convert.ToInt32(Session["Bran"].ToString())) == true)
                {
                    Alert.Show("Delete Successful.");
                }
                else
                {
                    Alert.Show("You can't delete.Because it is being used. ");
                }

            }
        }

        protected void _lbtViewDetails_Command(object sender, CommandEventArgs e)
        {
            Session["Bran"] = Convert.ToInt32(e.CommandArgument.ToString());
            Response.Redirect("../Object One/BranchDetail.aspx");
        }

        protected void _lbtViewEmployees_Command(object sender, CommandEventArgs e)
        {
            Session["Acc"] = Convert.ToInt32(e.CommandArgument.ToString());
            loadGR1();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (bd.DeleteBran(Convert.ToInt32(Session["Bran"].ToString())) == true)
            {
                Alert.Show("Delete Successful");
            }
            else
            {
                Alert.Show("you can not delete because it is being used ");
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            tb = dg.SearchBranch( int.Parse( DropDownList1.SelectedValue.ToString()));
            GridView1.DataSource = tb;
            GridView1.DataBind();
            Label7.Text = tb.Rows.Count.ToString();
        }

        protected void _grwAllEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }
    }
}